<?php
namespace My\Controller;

use Utuo\BackgroundController;

class GrouponController extends BackgroundController {
	
	private $status = array(
		'0' => '禁用',
		'1' => '启用',
	);

	public function _initialize() {
		$this->setControllerTitle('团购活动管理');
		$this->setActionTitle(array(
			'index' => '活动列表',
			'add' => '添加活动',
			'modify' => '活动编辑',
			'recycle' => '回收站',
			'orderList' => '订单列表',
		));
		$this->setActionNav(array(
				'index',
				'add',
				'recycle'
		));
	}
	
	public function indexAction() {
		$this->getLists(0);
	}
	
	public function recycleAction() {
		$this->getLists(1);
	}
	
	public function getLists( $is_deleted ) {
		$page = $this->getPage();
		$pagesize = $this->getPageSize();
		$lists = M('Groupon')->where("cid=%d and is_deleted=%d", $this->aid, $is_deleted)->limit($pagesize)->page($page)->order("id desc")->select();
		$count = M('Groupon')->where("cid=%d and is_deleted=%d", $this->aid, $is_deleted)->count();
		$this->assign('grouponLists', $lists);
		$this->showPage($count, $pagesize);
		$this->display();
	}
	
	/**
	 * 添加页
	 */
	public function addAction() {
		$this->assign("groupon", array(
			'status' => $this->getRadio('status', $this->status, 0),
		));
		$this->display('save');
	}
	
	/**
	 * 修改页
	 */
	public function modifyAction() {
		$config = D("Groupon")->getOneById();
		$config['status'] =  $this->getRadio('status', $this->status, $config['status']);
		$this->assign("groupon", $config);
		$this->display("save");
	}
	
}